<?php
/**
 * User: jewens
 */
class Conf extends MY_Admin_Controller
{
    public function index()
    {
    	$page = intval($this->input->get_post('page'));
    	$page = $page ? $page : 1;
    	
    	$limit = 20;
    	$offset = ($page-1) * $limit;
    	
        $this->load->model('common/Model_conf','c');
        $total_rows = $this->c->count();
        
        //分页
        $this->load->library('pagination');
         
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $limit;
        $config['base_url'] = '/system/conf/index';
         
        $this->pagination->initialize($config);
        $show_page = $this->pagination->create_links();
        
        //读取数据
        $list = $this->c->lists($offset, $limit);

        $data = array(
            'list' => $list,
        	'show_page'   => $show_page,
        	'total_rows'  => $config['total_rows'],
        );

        $this->load->view('admin/system/conf/index', $data);
    }
    
    public function edit()
    {
    	$cid = intval($this->input->get_post('cid'));
    	
    	$this->load->model('common/Model_conf','c');
    	$info  = $this->c->getOne(array('cid'=>$cid));
    
    	$this->load->view('admin/system/conf/edit', array('info'=>$info));
    }
    
    public function save()
    {
    	$cid = intval($this->input->get_post('cid'));
    	 
    	$data = array(
    			'title'        => $this->input->get_post('title'),
    			'name'         => $this->input->get_post('name'),
    			'value'        => $this->input->get_post('value'),
    			'create_time'  => date('Y-m-d H:i:s'),
    	);
    
    	$this->load->model('common/Model_conf','c');
    	$this->c->save($data, $cid);
    	
    	$this->load->helper('url');
    	redirect(url('admin').'system/conf/index');
    }
}